/**
 * Created by Administrator on 2018/2/5.
 */

define(function(require, exports, module) {
    var $=require('zepto');
    cn=require('conment');
    api=require('api');
    module.exports = {
        rex:{
            revemp:/^[\u4E00-\u9FA5]+$/,
            msg:'',
        },
        bindBank_Rex:function(a,b,c,d){
            return a==''?(this.rex.msg='请输入持卡人姓名',false)
                :!(this.rex.revemp).test(a)?(this.rex.msg='姓名输入格式有误',false)
                    :b==''?(this.rex.msg='请输入卡号',false)
                        :c==''?(this.rex.msg='请选择银行卡',false)
                            :d==''?(this.rex.msg='请输入开户行信息',false):true
        },

        getUserInfo:function () {
            const _this=this;
            cn.Ajax(api.isLogin,{
            },function(d){
                if(d.flag==1&&(d.name!=''||name!=null)){
                    $("#bank_name").val(d.name);
                    $("#bank_name").attr('disabled',true)
                }
            },'post')
        },
        bind_btn:function(){
            const _this=this;
            const x=$.trim($('#bank_name').val());
            const s=$.trim($('#bank_card').val());
            const z=$.trim($('#select-card').val());
            const w=$.trim($('#bank_ip').val());
            const bi=$.trim($('#cardId').val());
            if(!_this.bindBank_Rex(x,s,z,w)){
                cn.alert(_this.rex.msg)
                return false
            }else {
                cn.Ajax(api.bankcardAdd,{
                    name:x,
                    bankcardNo:s,
                    bankName:encodeURI(z),
                    bankcardBranch:encodeURI(w),
                    hxBankId:bi,
                },function(d){
                    if(d.flag==1){
                        cn.alert(d.message);
                        setTimeout(function (){
                            window.location.href='/view/setting.html'
                        },1000)
                    }else {
                        cn.alert(d.message)
                    }


                },'post')
            }
        },
        init:function () {
            const _this=this;
            _this.getUserInfo()
            $('#bindBank_btn').on('click',function () {
                _this.bind_btn()
            })
        },
    }

});